I have a parent window and two children windows. I want the child windows to display text, buttons, text fields, and a checkbox. I remembered to specify the WS_EX_CONTROLPARENT argument in the main window definition, so I don't think the parent window is my problem.
Here are the windows that I declare (they are in the WM_CREATE case):
Code:
HWND win1 = CreateWindowExW(NULL,
L"STATIC",
NULL,
WS_VISIBLE|WS_CHILD|SS_EDITCONTROL,
10,//x
50,//y
400,//width
200,//height
hwnd,
HMENU(WIN1),
GetModuleHandle(NULL),
NULL);
HWND win2 = CreateWindowExW(NULL,
L"STATIC",
NULL,
WS_VISIBLE|WS_CHILD|SS_EDITCONTROL,
10,//x
300,//y
200,//width
450,//height
hwnd,
HMENU(WIN2),
GetModuleHandle(NULL),
NULL);
HWND button1 = CreateWindowExW(NULL,
L"BUTTON",
L"BUTTON1",
WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,
25,//x
200,//y
150,//width
24,//height
win2,
(HMENU)BUTTON1,
GetModuleHandle(NULL),
NULL);
HWND button2 = CreateWindowExW(NULL,
L"BUTTON",
L"BUTTON2",
WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,
25,//x
250,//y
150,//width
24,//height
win2,
(HMENU)BUTTON2,
GetModuleHandle(NULL),
NULL);
HWND check = CreateWindowExW(NULL,
L"BUTTON",
NULL,
WS_VISIBLE|WS_CHILD|BS_AUTOCHECKBOX,
170,//x
400,//y
16,//width
16,//height
win2,
HMENU(BUTTON3),
GetModuleHandle(NULL),
NULL);
HWND text1 = CreateWindowExW(NULL,
L"EDIT",
NULL,
WS_VISIBLE|WS_CHILD|WS_BORDER,
150,//x
400,//y
25,//width
16,//height
win2,
HMENU(TEXT1),
GetModuleHandle(NULL),
NULL);
HWND text2 = CreateWindowExW(NULL,
L"EDIT",
NULL,
WS_VISIBLE|WS_CHILD|WS_BORDER,
150,//x
650,//y
25,//width
16,//height
win2,
HMENU(TEXT2),
GetModuleHandle(NULL),
NULL);
All of the above are then passed through EnableWindow() and set to TRUE.
Here is all of my code for the WM_PAINT case:
Code:
HDC hdc = BeginPaint(hwnd, &ps);
HDC hdc2 = BeginPaint(win1, &ps);
HDC hdc3 = BeginPaint(win2, &ps);
LPCWSTR title = L"Title";
LPCWSTR win1Label[5] = {L"A", L"B", L"C", L"D",
L"E"};
LPCWSTR win2Label[7] = {L"E", L"F", L"G", L"H",
L"I", L"J", L"K"};
long lfHeightTitle = -MulDiv(20, GetDeviceCaps(hdc, LOGPIXELSY), 72);
long lfHeightLabel = -MulDiv(12, GetDeviceCaps(hdc2, LOGPIXELSY), 72);
HGDIOBJ titleFont = CreateFont(lfHeightTitle, 0, 0, 0, 0, TRUE, 0, 0, 0, 0, 0, 0, 0, L"Times New Roman");
HGDIOBJ win1Font = CreateFont(lfHeightLabel, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"Times New Roman");
HGDIOBJ win2Font = win1Font;
SelectObject(hdc, titleFont);
SetBkMode(hdc, TRANSPARENT);
TextOut(hdc, 0, 0, title, 15);
EndPaint(hwnd, &ps);
SelectObject(hdc3, win2font);
SetBkMode(hdc3, TRANSPARENT);
TextOut(hdc3, 0, 0, win2Label[0], 1);
TextOut(hdc3, 0, 50, win2Label[1], 1);
TextOut(hdc3, 0, 100, win2Label[2], 1);
TextOut(hdc3, 0, 150, win2Label[3], 1);
//leave room for buttons!
TextOut(hdc3, 0, 300, win2Label[4], 11);
TextOut(hdc3, 0, 350, win2Label[5], 11);
TextOut(hdc3, 0, 400, win2Label[6], 11);
EndPaint(win2, &ps);
SelectObject(hdc2, mainLabelFont);
SetBkMode(hdc2, TRANSPARENT);
TextOut(hdc2, 0, 0, win1Label[0], 1);
TextOut(hdc2, 0, 20, win1Label[1], 1);
TextOut(hdc2, 0, 40, win1Label[2], 1);
TextOut(hdc2, 0, 60, win1Label[3], 1);
TextOut(hdc2, 0, 80, win1Label[4], 1);
EndPaint(win1, &ps);
RedrawWindow(hwnd, NULL, NULL, RDW_NOERASE | RDW_UPDATENOW);
RedrawWindow(win1, NULL, NULL, RDW_NOERASE | RDW_UPDATENOW);
RedrawWindow(win2, NULL, NULL, RDW_NOERASE | RDW_UPDATENOW);
I should also point out that any rect validation makes my window flicker and that the text is Unicode-formatted (hence the L in front of all text).
Is there any way I can print this text?